package model;

import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import connection.Conexao;
import javax.swing.JOptionPane;

/**
 * Define as regras de negocio para a classe de relatorios;
 *
 * @author Janio Luiz Antunes
 * @author Marcel Vinicius Kohls
 * @see http://code.google.com/p/sysdesk-java/
 *
 */

public class Relatorios {

    JasperPrint jasperPrint;

    public void gerarNovoRelatorio (String relatorioSolicitado) {

        Map parameters = new HashMap();
            
        try {
            jasperPrint = JasperFillManager.fillReport(relatorioSolicitado, parameters, Conexao.getConnection());
            JasperViewer viewer = new JasperViewer(jasperPrint, false);
            viewer.setTitle("Relatório solicitado");
            viewer.setVisible(true);
        } catch (JRException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao gerar relatório \n" + ex.getMessage());
        }        
    }
}
